<template>
	<view>

	<view class="cu-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar fixed bgColor " :style="style"
				:class="[bgImage!=''?'none-bg text-white bg-img':'']">
				<view class="action" @click="openCategory" v-if="iscategory">
					<text class="">筛选</text>
					
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content">{{title}}</slot>
				</view>

			</view>
		</view>


		<Loading class="loading1" v-show="!isLoading" :isStatus='loadStatus'></Loading>

		<basics v-if="PageCur=='basics'" :courseID='courseId' ref="basicsList" @changeTitle="changeT"></basics>
		<RuanJian v-if="PageCur=='ruanjian'"></RuanJian>
		<myself v-if="PageCur=='myself'" ref="changeMyself"></myself>
		<view class="cu-bar tabbar bg-white shadow foot" v-show="isLoading">
			<view class="action" @click="NavChange" data-cur="basics">
				<view class='cuIcon-cu-image'>
					<image :src="'/static/tabbar/basics' + [PageCur=='basics'?'_cur':''] + '.png'"></image>
				</view>
				<view :class="PageCur=='basics'?'text-green':'text-gray'">首页</view>
			</view>

	<!-- 		<view class="action" @click="NavChange" data-cur="ruanjian">
				<view class='cuIcon-cu-image'>
					<image :src="'/static/tabbar/ruanjian' + [PageCur == 'ruanjian'?'_cur':''] + '.png'"></image>
				</view>
				<view :class="PageCur=='plugin'?'text-green':'text-gray'">软件</view>
			</view> -->
			<view class="action" @click="NavChange" data-cur="myself">
				<view class='cuIcon-cu-image'>
					<image :src="'/static/tabbar/about' + [PageCur == 'myself'?'_cur':''] + '.png'"></image>
				</view>
				<view :class="PageCur=='plugin'?'text-green':'text-gray'">关于</view>
			</view>
		</view>
	</view>
</template>
<script>
	import Vue from 'vue'
	import RuanJian from "../software/home.vue"
	export default {
		components: {
			RuanJian
		},
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				title: this.CON.CON.title,
				PageCur: 'basics',
				courseId: "",
				isLoading: false,
				iscategory:true,
				loadStatus: 'load',
				meanList: {
					basics: {
						title: "我的推荐"
					},
					ruanjian: {
						title: "我的软件"
					},
					myself: {
						title: "关于"
					}

				}

			}
		},
		computed: {
			style() {
				var StatusBar = this.StatusBar;
				var CustomBar = this.CustomBar;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		onShareAppMessage(res) {
			console.log("分享的openid " + this.initCode);
			return {
				title: "乐知课程艺术中心",
				path: '/pages/index/index?userCode=' + this.initCode
			}

		},
		onUnload: () => {
			console.log("返回了");
		},
		onLoad(option) {
			Vue.prototype.$coupon = {};
			Vue.prototype.$openid = "";
			Vue.prototype.initCode = "";
			this.isLoading = true;
			Vue.prototype.$userCode = (option.userCode ?? '');
			this.courseId = option.courseId;
		},
		methods: {
			changeT(name){
				this.title=name;
			},
			/**
			 * 检查信息私服哦发生变化
			 */
			checkInfo() {
				let checkLogin = () => {
					uni.showModal({
						title: "提示",
						content: "用户信息发生变化,是否重新加载",
						success: (res) => {
							if (res.confirm) {
								this.reLogin();
							}
						}
					})
				}
				uni.getProvider({
					service: 'oauth',
					success: (res) => {
						if (~res.provider.indexOf('weixin')) {
							uni.login({
								provider: 'weixin',
								success: (loginRes) => {
									let appid = this.Reques.appid; //appid
									let url = "xcx/weixin.api.php";
									let data = {
										"action": "getWeixinUserInfoByCode",
										"appId": appid,
										"code": loginRes.code
									};
									//请求接口
									this.Reques.request(url, 'GET', data).then((res) => {
										if (res.statusCode == 200 && res.data.code == 0) {
											(this.$openid != res.data.openId) ? checkLogin
												(): "";
										}
									}, (err) => {
										console.log("获取失败");

									});
								}
							});
						}
					}
				});
			
			},
			/**
			 * 打开分类管理
			 */
			openCategory(){
				this.$refs.basicsList.changeCategory();
			},

			/**
			 * 回调更新
			 * @param {Object} type
			 */
			upData: function(type) {
				(this.PageCur == 'myself') ? (this.$refs.changeMyself.upadteVue()) : "";
				this.$forceUpdate();
			},
			NavChange: function(e) {
				
				this.PageCur = e.currentTarget.dataset.cur;
				this.title=this.meanList[this.PageCur].title;
				(this.PageCur=="basics")?this.iscategory=true:this.iscategory=false;
			}
		}


	}
</script>
